<template>
  <!-- 排队管理页面弹出框-->
  <el-dialog
    title="轧差排队管理申请录入排队管理"
    center
    :visible.sync="open"
    width="1024px"
    :close-on-click-modal="false"
    @close="closeFn"
  >
    <div style="height: 460px">
      <ht-table
        ref="dataTable"
        :showSerialNumber="false"
        :multi-select="false"
        :dictMap="dictMap"
        :reqConfig="reqConfig"
        :initData="false"
        :randomRowKey="true"
        :canHideColumns="false"
        :canHideSearch="false"
        :canRefresh="false"
        :queryParams="queryParams"
        :tableBindColumns="tableBindColumns"
        :opButtonList="opButtonList"
        style="height: 100%"
      >
        <template v-slot:singSelect="slotProps">
          <el-radio-group v-model="temoR" @input="singleChange(slotProps.row)">
            <el-radio :label="slotProps.row.seqNum">
              <i></i>
            </el-radio>
          </el-radio-group>
        </template>
      </ht-table>
    </div>
    <el-row type="flex" style="margin-top: 20px">
      <el-col :span="2">
        <label>备注：</label>
      </el-col>
      <el-col :span="22">
        <el-input :rows="2" v-model="remarks" type="textarea" maxlength="256" show-word-limit/>
      </el-col>
    </el-row>
    <div slot="footer" class="dialog-footer">
      <el-button icon="el-icon-top" type="primary" @click="adjustTop">调至队首</el-button>
      <el-button icon="el-icon-bottom" type="primary" @click="adjustEnd">调至队尾</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { detailSearch, tofirst, toend } from "@/api/cnaps/nets/queueMng/nets_queue_manage_entry.js";
import { log } from "util";
import { amountThousandsFormatter } from "@/utils/table_col_formatter";
export default {
  name: "QueueManage",
  components: {},
  props: {
    dictMap: {
      type: Object,
      default: () => {
        return {};
      },
    },
    pkgId: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      temoR: "",
      remarks: "",
      reqConfig: detailSearch,
      // 是否显示弹出层
      open: false,
      currentRow: [],
      // 查询参数
      queryParams: {
        id: "",
      },
      formOptions: [],
      opButtonList: () => {
        return [];
      },
      tableBindColumns: [
        {
          label: "",
          prop: "singSelect",
          width: "50",
          sortable: false,
          customSlot: true,
        },
        {
          label: `报文标识号`,
          prop: "txnOriPkgId",
          width: "170",
          sortable: false,
        },
        {
          label: `发起参与机构`,
          prop: "txnOriSender",
          width: "160",
          sortable: false,
        },
        {
          label: `报文类型`,
          prop: "txnOriMsgType",
          width: "100",
          //   dictCode: "PKG_STATUS",
          sortable: false,
        },
        {
          label: `货币种类`,
          prop: "curcd",
          //   dictCode: "PROCESSSTATUS",
          sortable: false,
        },
        {
          label: `金额`,
          prop: "amount",
          width: "160",
          type: "price",
          sortable: false,
        },
        {
          label: `排队顺序号`,
          prop: "seqNum",
          width: "160",
          sortable: false,
        },
        {
          label: `应答接收时间`,
          prop: "rcvTime",
          width: "160",
          type: "date",
          sortable: false,
        },
      ],
    };
  },
  mounted() {},
  watch: {
    open(d) {
      if (d) {
        this.$nextTick(() => {
          this.$set(this.queryParams, "id", this.pkgId);
          this.$refs.dataTable.doQuery();
          this.temoR = "";
          this.currentRow = [];
        });
      }
    },
  },
  methods: {
    singleChange(val) {
      this.currentRow = [];
      this.currentRow.push(val);
    },
    // 调至队首
    adjustTop() {
      if (this.currentRow.length != 1) {
        this.msgWarning("请选择一条数据！");
        return;
      }
      let detailArr = [];
      let topObj = {
        0: true,
        txnOriPkgId: this.currentRow[0].txnOriPkgId,
        seqNum: this.currentRow[0].seqNum,
        txnOriMsgType: this.currentRow[0].txnOriMsgType,
        txnOriSender: this.currentRow[0].txnOriSender,
      };
      detailArr.push(topObj);
      let topData = {
        detail: detailArr,
        id: this.pkgId,
        btSelectItem: "on",
        remarks: this.remarks,
      };
      console.log(topData, "topData000000");

      tofirst(topData).then((res) => {
        console.log(res, "调至队首");
        this.msgSuccess("已成功调至队首！");
        this.open = false;
        this.$emit("editComplete", true);
      });
    },
    // 调至队尾
    adjustEnd() {
      if (this.currentRow.length != 1) {
        this.msgWarning("请选择一条数据！");
        return;
      }
      let detailArr = [];
      let endObj = {
        0: true,
        txnOriPkgId: this.currentRow[0].txnOriPkgId,
        seqNum: this.currentRow[0].seqNum,
        txnOriMsgType: this.currentRow[0].txnOriMsgType,
        txnOriSender: this.currentRow[0].txnOriSender,
      };
      detailArr.push(endObj);
      let endData = {
        detail: detailArr,
        id: this.pkgId,
        btSelectItem: "on",
        remarks: this.remarks,
      };
      toend(endData).then((res) => {
        console.log(res, "调至队尾");
        this.msgSuccess("已成功调至队尾！");
        this.open = false;
        this.$emit("editComplete", true);
      });
    },
    // 表单重置
    reset() {
      this.resetForm("detailsForm");
      // this.$set(this, "form", {});
    },
    // 关闭回掉
    // handleClose(done) {
    //   this.$confirm("确认关闭？")
    //     .then(_ => {
    //       this.reset();
    //       done();
    //     })
    //     .catch(_ => {});
    // },
    closeFn() {
      this.open = false;
    },
    show() {
      this.open = true;
    },

    cancel() {
      this.open = false;
      this.reset();
    },
  },
};
</script>
